﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp7
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private int Id;

        public Form2(int id, string name, int age, int score)
        {
            InitializeComponent();
            this.Id = id;
            textBox1.Text = name;
            textBox2.Text = age.ToString();
            textBox3.Text = score.ToString();
        }
        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            var name = textBox1.Text;
            var age = textBox2.Text;
            var score = textBox3.Text;
            if (this.Id > 0)
            {
                var sql = string.Format("update Students set StudentNames='{0}',Age={1},Score={2} where Id={3}", name, age, score, this.Id);
                Class1.AddOrUpadteOrDelete(sql);
                MessageBox.Show("更新成功");
            }
            else {
                var sql = string.Format("insert into Students (StudentsName,StudentsAge,StudentsScore)values('{0}',{1},{2})", name, age, score);
                Class1.AddOrUpadteOrDelete(sql);
                MessageBox.Show("添加成功！", "提示");

            }
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }
    }
}
